package com.project.frba.bifront.client.model;

import java.util.HashMap;
import java.util.Map;

public class ColumnCounter {
	
	private Map<Integer, Integer> columnsByRow = new HashMap<Integer, Integer>();
	private Integer firstIndex;
	
	public ColumnCounter(Integer firstIndex) {
		this.firstIndex = firstIndex;
	}
	
	public void addColumn(Integer row){
		if(columnsByRow.get(row) == null){
			columnsByRow.put(row, 1);
		} else {
			Integer value = columnsByRow.get(row);
			columnsByRow.put(row, value+1);
		}
		
	}
	
	public Integer getColumnsForRow(Integer row){
		if(columnsByRow.get(row) == null){
			return 0;
		}
		return columnsByRow.get(row);
	}

	
	public Integer getRealPosition(Integer absolutePosition, Integer indexRow){
		return (absolutePosition - firstIndex) + getColumnsForRow(indexRow);
		
	}

}
